//
//  Segment.m
//  GeoData
//
//  Created by zhenhua zhou on 12-7-7.
//  Copyright (c) 2012年 ECUST. All rights reserved.
//

#import "Segment.h"

@implementation Segment

@synthesize Name,Description,TurnType,TurnPoint,Length,TrafficLevel, MaxPos, MinPos;
@synthesize Waypoints = mWaypoints;

-(Segment *) init
{
    self = [super init];
    if(self)
    {
        if(mWaypoints==nil)
        {
            mWaypoints = [[NSMutableArray alloc] init];
        }
        if(Name==nil)
        {    
            Name = [[NSString alloc] init];
        }
        
        if(Description==nil)
        {
            Description = [[NSString alloc] init];
        }
        if(MaxPos==nil)
        {
            MaxPos = [[GeoPos alloc] init];
        }
        if(MinPos==nil)
        {
            MinPos = [[GeoPos alloc] init];
        }

        Length = 0;
        TrafficLevel = 0;
    }
    
    return self;
}

- (void)dealloc
{
    if(mWaypoints)
    {
        [mWaypoints removeAllObjects];
        [mWaypoints dealloc];
    }
    if(Name)
    {
        [Name dealloc];
    }
    if(Description)
    {
        [Description dealloc];
    }
    
    [super dealloc];
}

- (void) addwaypoint:(Waypoint *)obj
{
    if(mWaypoints==nil)
    {
        mWaypoints = [[NSMutableArray alloc] init];
    }
    
    [mWaypoints addObject:obj];
}
- (void) insertWaypoint:(Waypoint *)obj atIndex:(int32_t)index
{
    if(mWaypoints==nil)
    {
        mWaypoints = [[NSMutableArray alloc] init];
    }
    
    [mWaypoints insertObject:obj atIndex:index];
}

- (int) getDistance
{
    int result = 0;
    for( Waypoint * waypoint in mWaypoints)
    {
        if(waypoint == nil)
            continue;
        result += [waypoint.Distance intValue];
        
    }
    
    return result;
}


@end
